package com.fisherman.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @User: fisherman
 * @Date: 2020/5/21 9:11
 */
@Component
public class Dog implements ApplicationContextAware {

    private  ApplicationContext applicationContext;  //保存容器

    public Dog(){
        System.out.println("dog....constructor...");
    }
    @PostConstruct  //对象创建并赋值之后调用
    public void init(){
        System.out.println("dog...@PostConstruct//对象创建并赋值之后调用");
    }
    @PreDestroy    //容器移除对象之前
    public void detroy(){
        System.out.println("dog...@PreDestroy//容器移除对象之前");
    }

    //保存容器
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }
}
